package com.apes.framework.jpa.logger;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.jpa.tuple.date.DateTime;
import com.apes.framework.plugin.outbox.annotation.OutBoxExclude;
import com.apes.framework.util.DateUtil;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenerationTime;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * 功能：业务单据关联关系
 *
 * @author xul
 * @create 2021-09-01 10:09
 */
@OutBoxExclude
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ApesRelation.CONST_TABLE_NAME, indexes = {
        @Index(columnList = "business_key, business_type", unique = true),
        @Index(columnList = "source_business_key, source_business_type")
})
public class ApesRelation extends BaseModel {
    public static final String CONST_TABLE_NAME = "ir_relation";

    @Id
    @Column(name = "id")
    @Comment("编码")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "业务单据关联关系")
    private long id;

    @Column(name = "business_type", length = 125)
    @Comment("单据类型")
    private String businessType;

    @Column(name = "business_key", length = 60)
    @Comment("单据编码")
    private String businessKey;

    @Column(name = "business_create_date", updatable = false)
    @Comment("单据创建时间")
    private Date businessCreateDate;

    @Column(name = "source_business_type", length = 125)
    @Comment("上游单据类型")
    private String sourceBusinessType;

    @Column(name = "source_business_key", length = 60)
    @Comment("上游单据编码")
    private String sourceBusinessKey;


    public ApesRelation() {
    }

    public ApesRelation(String businessType, String businessKey, Date businessCreateDate, String sourceBusinessType, String sourceBusinessKey) {
        this.businessType = businessType;
        this.businessKey = businessKey;
        this.sourceBusinessType = sourceBusinessType;
        this.sourceBusinessKey = sourceBusinessKey;
        this.businessCreateDate = businessCreateDate;
    }
}
